'use strict';
const moment = require('moment');
module.exports = app => {
  const { INTEGER, STRING, DATE } = app.Sequelize;
  const Application = app.model.define('application', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    staff: {
      type: INTEGER,
    },
    applytime: {
      type: DATE,
    },
    type: {
      type: STRING,
    },
    num: {
      type: INTEGER,
    },
    allow: {
      type: INTEGER,
    },
    result: {
      type: STRING,
    },
    info: {
      type: STRING,
    },
    created_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('created_at')).format(
          'YYYY-MM-DD HH:mm:ss'
        );
      },
    },
    updated_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('updated_at')).format(
          'YYYY-MM-DD HH:mm:ss'
        );
      },
    },
  });

  Application.associate = () => {
    Application.belongsTo(app.model.Sys.User, {
      foreignKey: 'staff',
    });
    Application.hasMany(app.model.Contract.Contract, {
      foreignKey: 'application_id',
    });
  };
  return Application;
};
